/**
 * 整合api
 */
import express from "express";
const router = express.Router();
import { dbContext } from "../database/initialize.js";

import other from "./other/index.js";
import theme from "./theme/index.js";
import user from "./user/index.js";
import jsons from "./json/index.js";
import article from "./article/index.js"

// 路由中间件
router.use(async (req, res, next) => {
    try {
        await dbContext.isDatabaseInitialized;
        
        if (!dbContext.isDatabaseInitialized) {
            return res.status(503).json({ 
                success: false, 
                message: "数据库初始化失败",
                error: dbContext.databaseInitializationError?.message 
            });
        }
        next();
    } catch (err) {
        return res.status(503).json({ 
            success: false, 
            message: "数据库初始化失败",
            error: err.message 
        });
    }
});

router.use(other);
router.use(theme);
router.use(user);
router.use(jsons);
router.use(article);

export default router;